import 'dart:io';

import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:xiaomi/app/modules/tools/screenAdapter.dart';
import 'package:xiaomi/app/modules/tools/httpClient.dart';
import '../controllers/good_list_controller.dart';

class GoodListView extends GetView<GoodListController> {
  const GoodListView({super.key});
  @override
  Widget build(BuildContext context) {
    print(Get.arguments);
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        title: Container(
          width: ScreenAdapter.width(800),
          height: ScreenAdapter.height(90),
          decoration: BoxDecoration(
              color: Colors.black12, borderRadius: BorderRadius.circular(45)),
          child: Row(
            children: [
              Padding(
                padding: EdgeInsets.only(left: ScreenAdapter.width(15)),
                child: const Icon(Icons.search),
              ),
              Padding(
                padding: EdgeInsets.only(left: ScreenAdapter.width(15)),
                child: Text(
                  '手机',
                  style: TextStyle(fontSize: ScreenAdapter.fontSize(38)),
                ),
              )
            ],
          ),
        ),
        centerTitle: true,
      ),
      body: Stack(
        children: [
          /// 底部的Listview

          Obx(
            () => ListView.builder(
                controller: controller.scrollController,
                padding: EdgeInsets.fromLTRB(ScreenAdapter.height(15),
                    ScreenAdapter.height(100), ScreenAdapter.height(15), 0),
                itemCount: controller.goodlistData.length,
                itemBuilder: (context, index) {
                  return Column(
                    children: [
                      Container(
                        decoration: BoxDecoration(
                          color: Color.fromRGBO(243, 243, 243, 1),
                          borderRadius: BorderRadius.circular(10),
                        ),
                        margin: EdgeInsets.only(bottom: 10),
                        padding: EdgeInsets.fromLTRB(20, 10, 10, 10),
                        child: Row(
                          children: [
                            ///左侧图片

                            Container(
                              padding: EdgeInsets.only(right: 20),
                              width: ScreenAdapter.width(300),
                              // height: ScreenAdapter.height(350),
                              // decoration: const BoxDecoration(color: Colors.blue),
                              child: Image.network(
                                HttpClient.imageUrl(
                                    '${controller.goodlistData[index].pic}'),
                                fit: BoxFit.fitHeight,
                              ),
                            ),

                            /// 右侧的详情
                            Expanded(
                              child: Column(
                                children: [
                                  Align(
                                    alignment: Alignment.centerLeft,
                                    child: Text(
                                      '${controller.goodlistData[index].title}',
                                      textAlign: TextAlign.start,
                                      style: TextStyle(
                                          fontWeight: FontWeight.bold,
                                          fontSize: ScreenAdapter.fontSize(40)),
                                    ),
                                  ),
                                  Align(
                                    alignment: Alignment.centerLeft,
                                    child: Text(
                                        '${controller.goodlistData[index].subTitle}'),
                                  ),
                                  SizedBox(
                                    height: ScreenAdapter.height(15),
                                  ),
                                  Row(
                                    children: [
                                      Expanded(
                                          flex: 1,
                                          child: Column(
                                            children: [
                                              Text('CPU'),
                                              Text(
                                                'Hello G250',
                                                style: TextStyle(
                                                    fontSize:
                                                        ScreenAdapter.fontSize(
                                                            28)),
                                              ),
                                            ],
                                          )),
                                      Container(
                                        width: ScreenAdapter.width(2),
                                        height: ScreenAdapter.height(60),
                                        color: Colors.grey,
                                      ),
                                      Expanded(
                                          flex: 1,
                                          child: Column(
                                            children: [
                                              Text('高清拍摄'),
                                              Text('1300万像素',
                                                  style: TextStyle(
                                                      fontSize: ScreenAdapter
                                                          .fontSize(28))),
                                            ],
                                          )),
                                      Container(
                                        width: ScreenAdapter.width(2),
                                        height: ScreenAdapter.height(60),
                                        color: Colors.grey,
                                      ),
                                      Expanded(
                                          flex: 1,
                                          child: Column(
                                            children: [
                                              Text('超大屏'),
                                              Text('7.0英寸',
                                                  style: TextStyle(
                                                      fontSize: ScreenAdapter
                                                          .fontSize(28))),
                                            ],
                                          )),
                                    ],
                                  ),
                                  SizedBox(
                                    height: ScreenAdapter.height(15),
                                  ),
                                  Align(
                                    alignment: Alignment.centerLeft,
                                    child:
                                        Text.rich(TextSpan(children: <TextSpan>[
                                      TextSpan(
                                          text: '￥',
                                          style: TextStyle(
                                              fontSize:
                                                  ScreenAdapter.fontSize(28))),
                                      TextSpan(
                                          text:
                                              '${controller.goodlistData[index].price}',
                                          style: TextStyle(
                                              fontWeight: FontWeight.bold,
                                              fontSize:
                                                  ScreenAdapter.fontSize(40))),
                                      TextSpan(
                                          text: '起',
                                          style: TextStyle(
                                              fontSize:
                                                  ScreenAdapter.fontSize(28))),
                                    ])),
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                      // _getIndicatorView(),
                    ],
                  );
                }),
          ),
          // Obx(
          //   () => _getIndicatorView(),
          // ),

          Positioned(
            left: 0,
            right: 0,
            top: 0,
            child: Container(
              height: ScreenAdapter.height(100),
              width: double.infinity,
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: Row(
                children: controller.sortList.map((map) {
                  return Expanded(
                    flex: 1,
                    child: InkWell(
                      onTap: () {
                        // print('点击按钮');
                        controller.tapindex(map);
                      },
                      child: Obx(() => Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text(
                                '${map['title']}',
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                    color: controller.selectIndex.value ==
                                            map['id']
                                        ? Colors.orange
                                        : Colors.black),
                              ),
                              (map['id'] == 2 || map['id'] == 3)
                                  ? controller.sameItem.value == -1
                                      ? Icon(Icons.arrow_drop_down)
                                      : Icon(Icons.arrow_drop_up)
                                  : Text(''),
                            ],
                          )),
                    ),
                  );
                }).toList(),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _getIndicatorView() {
    if (controller.isEndding.value) {
      return Container(
        alignment: Alignment.center,
        width: double.infinity,
        height: ScreenAdapter.height(100),
        color: Colors.blue,
        child: Text('我也是有底线的'),
      );
      //   } else if (controller.isLoaddingMore.value) {
      //     return Center(
      //       child: CircularProgressIndicator(),
      //     );
    } else {
      return Container();
    }
  }
}
